<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="下订单会员id" prop="memberId">
      <el-input size="mini"  v-model="dataForm.memberId" placeholder="下订单会员id"></el-input>
    </el-form-item>
    <el-form-item label="订单编号" prop="orderNumber">
      <el-input size="mini"  v-model="dataForm.orderNumber" placeholder="订单编号"></el-input>
    </el-form-item>
    <el-form-item label="订单总金额" prop="orderPrice">
      <el-input size="mini"  v-model="dataForm.orderPrice" placeholder="订单总金额"></el-input>
    </el-form-item>
    <el-form-item label="订单类型(0：店内购买，1：线上购买）" prop="orderType">
      <el-input size="mini"  v-model="dataForm.orderType" placeholder="订单类型(0：店内购买，1：线上购买）"></el-input>
    </el-form-item>
    <el-form-item label="支付方式  0未支付 1支付宝  2微信  3银行卡" prop="orderPay">
      <el-input size="mini"  v-model="dataForm.orderPay" placeholder="支付方式  0未支付 1支付宝  2微信  3银行卡"></el-input>
    </el-form-item>
    <el-form-item label="订单是否已经发货" prop="isSend">
      <el-input size="mini"  v-model="dataForm.isSend" placeholder="订单是否已经发货"></el-input>
    </el-form-item>
    <el-form-item label="支付宝交易流水号码" prop="tradeNo">
      <el-input size="mini"  v-model="dataForm.tradeNo" placeholder="支付宝交易流水号码"></el-input>
    </el-form-item>
    <el-form-item label="发票抬头 个人 公司" prop="orderFapiaoTitle">
      <el-input size="mini"  v-model="dataForm.orderFapiaoTitle" placeholder="发票抬头 个人 公司"></el-input>
    </el-form-item>
    <el-form-item label="公司名称" prop="orderFapiaoCompany">
      <el-input size="mini"  v-model="dataForm.orderFapiaoCompany" placeholder="公司名称"></el-input>
    </el-form-item>
    <el-form-item label="发票内容" prop="orderFapiaoContent">
      <el-input size="mini"  v-model="dataForm.orderFapiaoContent" placeholder="发票内容"></el-input>
    </el-form-item>
    <el-form-item label="consignee收货人地址" prop="consigneeAddr">
      <el-input size="mini"  v-model="dataForm.consigneeAddr" placeholder="consignee收货人地址"></el-input>
    </el-form-item>
    <el-form-item label="订单状态： 0未付款、1已付款" prop="payStatus">
      <el-input size="mini"  v-model="dataForm.payStatus" placeholder="订单状态： 0未付款、1已付款"></el-input>
    </el-form-item>
    <el-form-item label="记录生成时间" prop="createTime">
      <el-input size="mini"  v-model="dataForm.createTime" placeholder="记录生成时间"></el-input>
    </el-form-item>
    <el-form-item label="记录修改时间" prop="updateTime">
      <el-input size="mini"  v-model="dataForm.updateTime" placeholder="记录修改时间"></el-input>
    </el-form-item>
    <el-form-item label="门店id" prop="storeId">
      <el-input size="mini"  v-model="dataForm.storeId" placeholder="门店id"></el-input>
    </el-form-item>
    <el-form-item label="门店名称" prop="storeName">
      <el-input size="mini"  v-model="dataForm.storeName" placeholder="门店名称"></el-input>
    </el-form-item>
    <el-form-item label="门店编码" prop="storeCode">
      <el-input size="mini"  v-model="dataForm.storeCode" placeholder="门店编码"></el-input>
    </el-form-item>
    <el-form-item label="创建人" prop="createUsername">
      <el-input size="mini"  v-model="dataForm.createUsername" placeholder="创建人"></el-input>
    </el-form-item>
    <el-form-item label="创建人id" prop="createUserId">
      <el-input size="mini"  v-model="dataForm.createUserId" placeholder="创建人id"></el-input>
    </el-form-item>
    <el-form-item label="修改人" prop="updateUsername">
      <el-input size="mini"  v-model="dataForm.updateUsername" placeholder="修改人"></el-input>
    </el-form-item>
    <el-form-item label="修改人id" prop="updateUserId">
      <el-input size="mini"  v-model="dataForm.updateUserId" placeholder="修改人id"></el-input>
    </el-form-item>
    <el-form-item label="是否可用 1:是" prop="status">
      <el-input size="mini"  v-model="dataForm.status" placeholder="是否可用 1:是"></el-input>
    </el-form-item>
    <el-form-item label="是否删除 1:是" prop="isDeleted">
      <el-input size="mini"  v-model="dataForm.isDeleted" placeholder="是否删除 1:是"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input size="mini"  v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>
    <el-form-item label="" prop="version">
      <el-input size="mini"  v-model="dataForm.version" placeholder=""></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="visible = false">取消</el-button>
      <el-button size="mini" type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          memberId: '',
          orderNumber: '',
          orderPrice: '',
          orderType: '',
          orderPay: '',
          isSend: '',
          tradeNo: '',
          orderFapiaoTitle: '',
          orderFapiaoCompany: '',
          orderFapiaoContent: '',
          consigneeAddr: '',
          payStatus: '',
          createTime: '',
          updateTime: '',
          storeId: '',
          storeName: '',
          storeCode: '',
          createUsername: '',
          createUserId: '',
          updateUsername: '',
          updateUserId: '',
          status: '',
          isDeleted: '',
          remark: '',
          version: ''
        },
        dataRule: {
          memberId: [
            { required: true, message: '下订单会员id不能为空', trigger: 'blur' }
          ],
          orderNumber: [
            { required: true, message: '订单编号不能为空', trigger: 'blur' }
          ],
          orderPrice: [
            { required: true, message: '订单总金额不能为空', trigger: 'blur' }
          ],
          orderType: [
            { required: true, message: '订单类型(0：店内购买，1：线上购买）不能为空', trigger: 'blur' }
          ],
          orderPay: [
            { required: true, message: '支付方式  0未支付 1支付宝  2微信  3银行卡不能为空', trigger: 'blur' }
          ],
          isSend: [
            { required: true, message: '订单是否已经发货不能为空', trigger: 'blur' }
          ],
          tradeNo: [
            { required: true, message: '支付宝交易流水号码不能为空', trigger: 'blur' }
          ],
          orderFapiaoTitle: [
            { required: true, message: '发票抬头 个人 公司不能为空', trigger: 'blur' }
          ],
          orderFapiaoCompany: [
            { required: true, message: '公司名称不能为空', trigger: 'blur' }
          ],
          orderFapiaoContent: [
            { required: true, message: '发票内容不能为空', trigger: 'blur' }
          ],
          consigneeAddr: [
            { required: true, message: 'consignee收货人地址不能为空', trigger: 'blur' }
          ],
          payStatus: [
            { required: true, message: '订单状态： 0未付款、1已付款不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '记录生成时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '记录修改时间不能为空', trigger: 'blur' }
          ],
          storeId: [
            { required: true, message: '门店id不能为空', trigger: 'blur' }
          ],
          storeName: [
            { required: true, message: '门店名称不能为空', trigger: 'blur' }
          ],
          storeCode: [
            { required: true, message: '门店编码不能为空', trigger: 'blur' }
          ],
          createUsername: [
            { required: true, message: '创建人不能为空', trigger: 'blur' }
          ],
          createUserId: [
            { required: true, message: '创建人id不能为空', trigger: 'blur' }
          ],
          updateUsername: [
            { required: true, message: '修改人不能为空', trigger: 'blur' }
          ],
          updateUserId: [
            { required: true, message: '修改人id不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '是否可用 1:是不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '是否删除 1:是不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ],
          version: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/sale/saleorder/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.memberId = data.saleOrder.memberId
                this.dataForm.orderNumber = data.saleOrder.orderNumber
                this.dataForm.orderPrice = data.saleOrder.orderPrice
                this.dataForm.orderType = data.saleOrder.orderType
                this.dataForm.orderPay = data.saleOrder.orderPay
                this.dataForm.isSend = data.saleOrder.isSend
                this.dataForm.tradeNo = data.saleOrder.tradeNo
                this.dataForm.orderFapiaoTitle = data.saleOrder.orderFapiaoTitle
                this.dataForm.orderFapiaoCompany = data.saleOrder.orderFapiaoCompany
                this.dataForm.orderFapiaoContent = data.saleOrder.orderFapiaoContent
                this.dataForm.consigneeAddr = data.saleOrder.consigneeAddr
                this.dataForm.payStatus = data.saleOrder.payStatus
                this.dataForm.createTime = data.saleOrder.createTime
                this.dataForm.updateTime = data.saleOrder.updateTime
                this.dataForm.storeId = data.saleOrder.storeId
                this.dataForm.storeName = data.saleOrder.storeName
                this.dataForm.storeCode = data.saleOrder.storeCode
                this.dataForm.createUsername = data.saleOrder.createUsername
                this.dataForm.createUserId = data.saleOrder.createUserId
                this.dataForm.updateUsername = data.saleOrder.updateUsername
                this.dataForm.updateUserId = data.saleOrder.updateUserId
                this.dataForm.status = data.saleOrder.status
                this.dataForm.isDeleted = data.saleOrder.isDeleted
                this.dataForm.remark = data.saleOrder.remark
                this.dataForm.version = data.saleOrder.version
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/sale/saleorder/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'memberId': this.dataForm.memberId,
                'orderNumber': this.dataForm.orderNumber,
                'orderPrice': this.dataForm.orderPrice,
                'orderType': this.dataForm.orderType,
                'orderPay': this.dataForm.orderPay,
                'isSend': this.dataForm.isSend,
                'tradeNo': this.dataForm.tradeNo,
                'orderFapiaoTitle': this.dataForm.orderFapiaoTitle,
                'orderFapiaoCompany': this.dataForm.orderFapiaoCompany,
                'orderFapiaoContent': this.dataForm.orderFapiaoContent,
                'consigneeAddr': this.dataForm.consigneeAddr,
                'payStatus': this.dataForm.payStatus,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime,
                'storeId': this.dataForm.storeId,
                'storeName': this.dataForm.storeName,
                'storeCode': this.dataForm.storeCode,
                'createUsername': this.dataForm.createUsername,
                'createUserId': this.dataForm.createUserId,
                'updateUsername': this.dataForm.updateUsername,
                'updateUserId': this.dataForm.updateUserId,
                'status': this.dataForm.status,
                'isDeleted': this.dataForm.isDeleted,
                'remark': this.dataForm.remark,
                'version': this.dataForm.version
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
